<template>
	<view style="padding: 20px;">
		<uni-forms :modelValue="loginForm">
			<!-- 输入账号（用户名） -->
			<uni-forms-item label="账号">
				<uni-easyinput type="text" v-model="loginForm.name" placeholder="请输入账号" />
			</uni-forms-item>
			<!-- 输入密码 -->
			<uni-forms-item label="密码">
				<uni-easyinput type="password" v-model="loginForm.password" placeholder="请输入密码" />
			</uni-forms-item>
			<!-- 登录按钮 -->
			<button style="margin-top: 10px;" type="primary" size="large" @click="onClickLogin">登录</button>
		</uni-forms>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loginForm: {
					name: "dingding", //用户名，仅仅测试方便
					password: "123456",
				},
			}
		},
		methods: {
			onClickLogin() {
				if (this.loginForm.name === "" || this.loginForm.password === "") {
					uni.showToast({ title: "账号或密码不能为空", icon: "error" });
					return;
				}

				//
				let params = this.loginForm;
				uni.request({
					url: 'http://localhost:5050/user/login',
					method: 'get',
					data: this.loginForm,
					header: { 'content-type': 'application/json' },
					// header: { 'content-type': 'application/x-www-form-urlencoded' }
				}).then(result => {
					console.log(result);
					if (result.data.code === 200) {
						uni.showToast({
							title: "登录成功！",
							icon: "success"
						});
					} else {
						uni.showToast({
							title: "登录失败！",
							icon: "success"
						});
					}

					//把返回的token在本地保存  
					//用户信息保存在本地

				})
			},

		},
	}
</script>

<style>

</style>